package com.cinyi.ormlite.web;

import javax.servlet.ServletContextEvent;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cinyi.ormlite.IContext;

/**
 * 
 * @author penghui
 *
 */
public class OrmliteContextListener extends ContextLoaderListener {
	/**
	 * Spring应用上下文环境
	 */
	private static ApplicationContext applicationContext;
	
	private IContext OrmliteWebContext ;

	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		applicationContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
		buildOrmliteWebContext(applicationContext);
	}

	public void buildOrmliteWebContext(ApplicationContext applicationContext2){
		OrmliteWebContext = new WebContext(applicationContext) ;
	}

	@Override
	public void contextDestroyed(ServletContextEvent event) {
		super.contextDestroyed(event);
	}

	public IContext getOrmliteWebContext() {
		return OrmliteWebContext;
	}
	
}
